// ==================================================================================
// Shared Genomics Project MPI Codebase
// Version 1.0 30/04/2010
//
// (c) 2010 University of Manchester all rights reserved
//
// This file is distributed under the GNU General Public License, Version 2.  
// Please see the file COPYING.txt for more details
// ==================================================================================

/*!
\file
\ingroup	gio
\brief		I/O Methods for Parrallised Filtering
*/

#ifndef _PFORMAT_H_
#define _PFORMAT_H_

#include "options.h"
#include "mapfile.h"

#ifdef __cplusplus
extern "C" {
#endif

/*!
\brief Write a summary of filter results to a text file
\details
	Lists all of the SNPs/People removed from a data-set and the reason for removal.<br>
\param [in] nSNPs No. SNPs in data-set
\param [in] all_snps SNP List
\param [in] snps_to_del Boolean array to flag if SNPs removed from data-set
\param [in] reasons_to_del Reason for SNP deletion
\param [in] stats Test statistic associated with the SNP deletion
\param [in] ops Filter options
\param [in] ldir Local working directory
\param [in] rdir Remote working directory
\param [in] nSamples No. Samples
\param [in] persons_to_del Boolean array to flag if persons removed from data-set
\param [in] missingness Array of Person missingness (call rates)
\returns 1 on success, 0 on failure
*/
int pformat_write_filter_log(int nSNPs, struct small_locus *all_snps, BOOL *snps_to_del, char *reasons_to_del, double *stats, struct selected_options *ops, char *ldir, char *rdir, int nSamples, BOOL *persons_to_del, double *missingness);

/*!
\brief Write the filtered dimensions of a allelic data-set to file.
\param [in] nSNPs No. SNPs in data-set
\param [in] nSamples No. Samples
\param [in] numprocs No. cores allocated to filtering
\param [in] snps_to_del Boolean array to flag if SNPs removed from data-set
\param [in] persons_to_del Boolean array to flag if persons removed from data-set
\param [in] ops Output file location
\returns 1 on success, 0 on failure
*/
int pformat_write_filter_dims(int nSNPs, int nSamples, int numprocs, BOOL *snps_to_del, BOOL *persons_to_del, struct selected_options *ops);

/*!
\brief Read the filtered dimensions of a allelic data-set from file.
\param [in] numprocs Pointer to store No. cores allocated to filtering
\param [in] nSNPs Pointer to store No. SNPs in data-set
\param [in] nSamples Pointer to store No. Samples
\param [in] ops input file location
\returns 1 on success, 0 on failure
*/
int pformat_read_filter_dims(int *numprocs, int *nSNPs, int *nSamples, struct selected_options *ops);

/*!
\brief Read fragments of filtered pedigree data (PED) from parallelised cores
\param [in] ops Input File location
\param [in] m SNP-major structure to store the allelic data
\returns 1 on success, 0 on failure
*/
int pformat_read_fbped_fragments(struct selected_options *ops, struct mapfile *m);

/*! 
\brief
*/
int pformat_alloc_samples(struct pedfile *p, int nSamples, double *phe_values, BOOL *persons_to_del, BOOL *missing, BOOL *sex);

/*!
\brief Remove the temporary data files associated with parrallelised filtering. 
\param [in] ops Temporary output file location
\returns 1 on success, 0 on failure
*/
int pformat_cleanup(struct selected_options *ops);

#ifdef __cplusplus
}
#endif

#endif  // _PFORMAT_H_
